using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dss.Core.Attributes;
using Microsoft.Robotics.Services.Sonar.Proxy;
using phys = Microsoft.Robotics.PhysicalModel.Proxy;
using System.ComponentModel;

namespace Devantech.Services.SD21.SonarPan
{
    #region State
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public class SD21SonarPanState
    {
        private DateTime _timestamp;
        private DateTime _starttime;
        private DateTime _endtime;
        private int _panTime;
        private int _minPulseWidth;
        private int _maxPulseWidth;
        private int[] _distanceMeasurements;
        private DateTime[] _timestamps;
        private bool _panningRight;
        private int _servoChannel;
        private double _drawScale;
        private phys.Pose _servoPose;
        private bool _enabled;
        private int  _outputHardwareIdentifier;
        private SonarState _outputSonarState;

        /// <summary>
        /// Summary of OutputSonarState.
        /// </summary>
        [DataMember, Description("")]
        public SonarState SonarState
        {
            get { return _outputSonarState; }
            set { _outputSonarState = value; }
        }

        /// <summary>
        /// Summary of OutputHardwareIdentifier.
        /// </summary>
        [DataMember, Description("")]
        public int  OutputHardwareIdentifier
        {
            get { return _outputHardwareIdentifier; }
            set { _outputHardwareIdentifier = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="SD21SonarPanState"/> is enabled.
        /// </summary>
        /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
        [DataMember, Description("")]
        public bool Enabled
        {
            get { return _enabled; }
            set { _enabled = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        [DataMember, Description("")]
        public int[] DistanceMeasurements
        {
            get { return _distanceMeasurements; }
            set { _distanceMeasurements = value; }
        }

        /// <summary>
        /// Gets or sets the timestamps.
        /// </summary>
        /// <value>The timestamps.</value>
        [DataMember, Description("")]
        public DateTime[] Timestamps
        {
            get { return _timestamps; }
            set { _timestamps = value; }
        }

        /// <summary>
        /// Gets or sets the timestamp.
        /// </summary>
        /// <value>The timestamp.</value>
        [DataMember, Description("")]
        public DateTime Timestamp
        {
            get { return _timestamp; }
            set { _timestamp = value; }
        }

        /// <summary>
        /// Gets or sets the start time.
        /// </summary>
        /// <value>The start time.</value>
        [DataMember, Description("")]
        public DateTime StartTime
        {
            get { return _starttime; }
            set { _starttime = value; }
        }

        /// <summary>
        /// Gets or sets the end time.
        /// </summary>
        /// <value>The end time.</value>
        [DataMember, Description("")]
        public DateTime EndTime
        {
            get { return _endtime; }
            set { _endtime = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [panning right].
        /// </summary>
        /// <value><c>true</c> if [panning right]; otherwise, <c>false</c>.</value>
        [DataMember, Description("")]
        public bool PanningRight
        {
            get { return _panningRight; }
            set { _panningRight = value; }
        }

        /// <summary>
        /// The time to do a full pan
        /// </summary>
        [DataMember, Description("")]
        public int PanTime
        {
            get { return _panTime; }
            set { _panTime = value; }
        }

        /// <summary>
        /// The desired servo pulse width
        /// </summary>
        [DataMember, Description("")]
        public int MinPulseWidth
        {
            get { return _minPulseWidth; }
            set { _minPulseWidth = value; }
        }

        /// <summary>
        /// The desired maximum servo pulse width
        /// </summary>
        [DataMember, Description("")]
        public int MaxPulseWidth
        {
            get { return _maxPulseWidth; }
            set { _maxPulseWidth = value; }
        }

        /// <summary>
        /// Gets or sets the servo channel.
        /// </summary>
        /// <value>The servo channel.</value>
        [DataMember, Description("")]
        public int ServoChannel
        {
            get { return _servoChannel; }
            set { _servoChannel = value; }
        }

        /// <summary>
        /// Gets or sets the draw scale.
        /// </summary>
        /// <value>The draw scale.</value>
        [DataMember, Description("")]
        public double DrawScale
        {
            get { return _drawScale; }
            set { _drawScale = value; }
        }

        /// <summary>
        /// Gets or sets the servo pose.
        /// </summary>
        /// <value>The servo pose.</value>
        [DataMember, Description("")]
        public phys.Pose ServoPose
        {
            get { return _servoPose; }
            set { _servoPose = value; }
        }

        private List<SonarBuffer> _sonars;

        /// <summary>
        /// Summary of Sonars.
        /// </summary>
        /// <value>The sonars.</value>
        [DataMember, Description("")]
        public List<SonarBuffer> Sonars
        {
            get { return _sonars; }
            set { _sonars = value; }
        }

        private List<int> _hardwareIdentifiers;

        /// <summary>
        /// Summary of HardwareIdentifiers.
        /// </summary>
        [DataMember, Description("")]
        public List<int> HardwareIdentifiers
        {
            get { return _hardwareIdentifiers; }
            set { _hardwareIdentifiers = value; }
        }
    }

    /// <summary>
    /// Used to store an array of readings
    /// and the latest sonar state
    /// </summary>
    [DataContract]
    public class SonarBuffer
    {
        private SonarState _state;
        private int[] _distanceMeasurements;
        private DateTime[] _timestamps;
        private bool _subscribed;

        /// <summary>
        /// Indicates whether we have succeeded in subscribing to the sonar.
        /// </summary>
        [DataMember, Description("")]
        public bool Subscribed
        {
            get { return _subscribed; }
            set { _subscribed = value; }
        }

        /// <summary>
        /// The latest Sonar State
        /// </summary>
        [DataMember, Description("")]
        public SonarState State
        {
            get { return _state; }
            set { _state = value; }
        }

        /// <summary>
        /// An array of distance measurements
        /// </summary>
        [DataMember, Description("")]
        public int[] DistanceMeasurements
        {
            get { return _distanceMeasurements; }
            set { _distanceMeasurements = value; }
        }

        /// <summary>
        /// The times at which the latest distance measurements arrived
        /// </summary>
        [DataMember, Description("")]
        public DateTime[] Timestamps
        {
            get { return _timestamps; }
            set { _timestamps = value; }
        }
    }

    #endregion
}
